

Ext.define('Holo.store.TripSpots', {
    extend: 'Ext.data.Store',
    requires: 'Holo.model.TripSpot',
    model: 'Holo.model.TripSpot',
    
    
    /**
     *  Remove the spot not selected anymore
     */
    removeOldInstance : function(arraySpotIdSelected){
        
        var tabSpotSelected = arraySpotIdSelected;
        var fn = function(relationTripSpot){
            var inSelectedSpotTab = false;    
            for (var i=0; i < tabSpotSelected.length; i++) {
		if(relationTripSpot.get('spot_id') == tabSpotSelected[i]){
                    inSelectedSpotTab = true;
                    break;
		}
	    }
            
            if(! inSelectedSpotTab){
                console.log('removing :' + relationTripSpot.get('id'));
                this.remove(relationTripSpot);
            }
        }
        
        this.each(fn, this) ;
    },
    
    arrayOfid : function(){
        var tabSpotId=[]
        var order, index;
           
        for (var i=0; i < this.count(); i++) {
           order = i + 1;
           index = this.findExact('list_order', order);
           tabSpotId.push(this.getAt(index).get('spot_id'));
        }
        return tabSpotId;
        
    }
    
});